

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                                                                  *
 *        *************************************************         *
 *        *©2021-2027 HT Corporation All rights reserved *          *
 *        *************************************************         *
 *                                                                  *
 * FileName    : ht_vi.h                                            *
 *                                                                  *
 * Author      : linus                                              *
 *                                                                  *
 * Email       : luoyaojun@haitutech.com                            *
 *                                                                  *
 * Date        : 2022-8-9                                           *
 *                                                                  *
 * Description :                                                    *
 *                                                                  *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef __HT_VI_H
#define __HT_VI_H

#include "ht_type.h"

typedef HT_S32 (*ht_vi_get_frame_cb)(HT_S32 viDev, HT_S32 viChn, HT_VOID *user, HT_FRAME frame_out);

typedef enum{
    HT_VI_CONNECT_STATE_UNKNOWN = 0,
    HT_VI_CONNECT_STATE_CONNECT,
    HT_VI_CONNECT_STATE_DISCONNECT
}HT_VI_CONNECT_STATUS;

struct ht_vi_connection_info{
	HT_U32 viDev;

	HT_U32 viChn;

	struct resolution res;

	HT_PIXEL_FORMAT pixel_fmt;

	HT_VI_CONNECT_STATUS status;
};

struct ht_vi_config{
    // 指定vi端的分辨率
    struct resolution res;

    // 兼容海思、瑞芯微平台的vi参数配置
    union {
		/*
		**	rockchip平台，dev_name为可选配置
		**	当不指定dev_name时，默认使用index id作为dev_name
		**	具体参考vi中stChnAttr属性配置
		*/
		const char *dev_name;
		HT_VI_MODE vi_mode;
    };
	
	/*
	**	通过getchnframe从chn取数据时需要设置，默认为0
	**	设置非0的情况下将vi chn绑定到后级时 dumpsys vi可看到get_cnt和release_cnt的差值为depth
	*/	
	HT_U32 depth;

	//	可选 v4l2内存类型，rk平台在HDMI输入或其他不经过isp的输入时需使用HT_MEMORY_TYPE_MMAP
	HT_MEMORY_TYPE mem_type;

	//	可选 输入 像素格式
	HT_PIXEL_FORMAT pixel_fmt;

};


HT_S32 ht_vi_dev_init(HT_S32 viDev);
HT_S32 ht_vi_dev_exit(HT_U32 viDev);

HT_S32 ht_vi_chn_init(HT_U32 viDev, HT_U32 viChn, struct ht_vi_config *);
HT_S32 ht_vi_chn_exit(HT_U32 viDev, HT_U32 viChn);

HT_S32 ht_vi_get_connection_info(HT_U32 viDev, HT_U32 viChn, struct ht_vi_connection_info *conn_info);

/*
**
**	WARNING：
**	wait_time非0时，无法通过ht_vi_chn_exit或ht_vi_dev_exit关闭该通道，会报unsupport command interrupt错误
**	
*/
HT_S32 ht_vi_chn_get_frame(HT_U32 viDev, HT_U32 viChn, HT_S32 wait_time, ht_vi_get_frame_cb cb, void *user);
HT_S32 ht_vi_chn_stop_frame(HT_U32 viDev, HT_U32 viChn);


HT_U64 ht_vi_frame_get_pts(HT_FRAME frame);


// for rest
int isp_init1();

#endif
